package com.cloud.order.service.impl;


import com.cloud.feign.clients.UserClient;
import com.cloud.feign.entity.Order;
import com.cloud.feign.entity.User;
import com.cloud.order.mapper.OrderMapper;
import com.cloud.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

//    @Autowired
//    private RestTemplate restTemplate;

    @Autowired
    private UserClient userClient;

    @Override
    public Order queryOrderById(Long orderId) {
        Order order = orderMapper.findById(orderId);
        Long userId = order.getUserId();

        // 用RestTemplate远程调用
//        String url = "http://user-service/user/getUser/" + userId; // 从注册中心中获取user服务
//        User user = restTemplate.getForObject(url, User.class);

        // 用Feign远程调用
        User user = userClient.findById(userId);

        order.setUser(user);

        return order;
    }
}
